/*
* ========== Copyright Header Begin ==========================================
* 
* OpenSPARC T1 Processor File: dump.h
* Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* 
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* 
* The above named program is distributed in the hope that it will be 
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
* 
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* 
* ========== Copyright Header End ============================================
*/
/*
 * Copyright (C) 2001, Sun Microsystems, Inc.
 */
#pragma ident	"@(#)1.1	02/04/09 SMI	dump.h"

#ifndef _DUMP_H
#define _DUMP_H

#include <stdio.h>

typedef struct {
  void *oldaddr;
  void *newaddr;
  unsigned int read:1;
} dt_addrs_t;

typedef struct {
  dt_addrs_t	*addrs;
  int		size;
  int		next;
} dumptab_t;

// helper functions...
void print_addr (FILE *f, void *vp);

// dump table stuff 
void dumptab_init(dumptab_t *dtp);
void dumptab_free(dumptab_t *dtp);
void dumptab_reset(dumptab_t *dtp);
dt_addrs_t* dumptab_lookup_old(dumptab_t *dtp, void *oldp);
dt_addrs_t* dumptab_lookup_new(dumptab_t *dtp, void *newp);
int dumptab_add(dumptab_t *dtp, void *oldp, void *newp);
void print_dumptab(dumptab_t *dtp);

extern dumptab_t dtab;

// dump functions
void dumpStructAddr (FILE *f, char *addr, const char *name, int size, int arrlen);
void dumpDynArrDelm (FILE *f, const char *name, int idx, int total);
void dumpScalar (FILE *f, const char *name, char *data, size_t size);
void dumpPtrArr (FILE *f, const char *name, char *data, size_t size, size_t arr_size);
void dumpArr (FILE *f, const char *name, unsigned char *data, size_t num, size_t size);
void dumpString (FILE *f, const char *name, char *str);

#define DUMPF_REQUIRED	0x1
#define DUMPF_STRING	0x2
#define DUMPF_PTR	0x4
#define DUMPF_NO_MALLOC	0x8
#define DUMPF_PTR_ARR	0x10

// restore stuff
struct restore_map_t {
  const char   	*name;
  size_t	offset;
  size_t	size;
  size_t       	index;
  unsigned int	flags;
  unsigned int	read:1;
};

// do you have to malloc these types?
#define NO_MALLOC_archglobals_t		1
#define NO_MALLOC_Serial_state_t	1
#define NO_MALLOC_Simge_state_t		1
#define NO_MALLOC_Tlb_entry_t		0
#define NO_MALLOC_schizo_state_t	1
#define NO_MALLOC_block_t		0
#define NO_MALLOC_blk_cache_t		0
#define NO_MALLOC_partfile_t		0
#define NO_MALLOC_pcidisk_state_t	1
#define NO_MALLOC_pcidisk_lunit_t	1
#define NO_MALLOC_Tlb_line_t		0
#define NO_MALLOC_Spit_mmu_t		1
#define NO_MALLOC_brkpoint_info_t	0
#define NO_MALLOC_FcpuT			1

unsigned char *
general_restore_type (char *dir, const char *filename, struct restore_map_t *map, unsigned char *rp, size_t size, int no_malloc); 
int dump_debugf_init (const char *fn);
void dump_debugf_close ();

#define DUMP_FNAME_SIZE	64
#define DUMP_DIRF_SIZE	272

#endif // _DUMP_H
